package com.zhengke.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhengke.common.object.Result;
import com.zhengke.common.util.FileExport;
import com.zhengke.pojo.Fwdxxtj;
import com.zhengke.service.FwdxxtjService;

@Controller
//@RequestMapping("analysis")
public class FwdxxtjController {
	 /**
     * ssx
     * */
	@Autowired
	private FwdxxtjService service;
	
	/**
	 * 到列表页面
	 * @return
	 */
	@RequestMapping("analysis!queryService.do")
	public String toQuery() {
		return "fwdxxtj/list";
	}
	
	/**
	 * 查询列表
	 * */
	@RequestMapping("fdj/list.do")
	@ResponseBody
	public Result queryAll(String startTime,String endTime,String quiz1,String quiz2,String quiz3,int page,int limit) {
		Result rs = null; 
		try {
			rs = service.quaryAll(startTime,endTime,quiz1,quiz2,quiz3,page, limit);
			return rs;
		} catch (Exception e) {
			e.printStackTrace();
		}  	
		return new Result();
	}

	
	
	/**
     * 查询父类
     */
	@RequestMapping(value="fdtj/list",method=RequestMethod.POST)
	@ResponseBody
	public Result querys(int area_parent_id, Integer area_deep) {
		Result rs = null;
		try {
		    rs = service.querys(area_parent_id, area_deep);
			return rs;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 查询二、三级分类
	 * */
	@RequestMapping(value="queryClassificationByName",method=RequestMethod.POST)
	@ResponseBody
	public Result querysName(String area_name) {
		Result rs = null;
		try {
		    rs = service.queryName(area_name);
		    rs.setCode("0");
			return rs;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	
	/**
     * export Excel
     * @param 
     * @param 
     * @param 
     * @param 
     */
    @SuppressWarnings("unchecked")
	@RequestMapping("fdj/export.do")
    public void exportExcel(String startTime,String endTime,String quiz1,String quiz2,String quiz3,HttpServletResponse response) {
    	Result rs = null;    	
    	try {
			 rs = service.quaryAll(startTime,endTime,quiz1,quiz2,quiz3,0, 0);
			 String[] topName = {"ID","名称", "时间","收入金额","订单数量","商品数量","订单金额","出库订单量"};
			 List<Object[]> list = new ArrayList<Object[]>();
			 for(Fwdxxtj fdj : (List<Fwdxxtj>)rs.getData()) {
				 Object [] obj =new Object[topName.length];
				 obj[0]=fdj.getArea_id();
				 obj[1]=fdj.getArea_name();
				 obj[2]=fdj.getTims();
				 obj[3]=fdj.getAmounts1();
				 obj[4]=fdj.getOrders1();
				 obj[5]=fdj.getGoods();
				 obj[6]=fdj.getAmounts2();
				 obj[7]=fdj.getOrders2();
				 list.add(obj);
			 }			 
			FileExport.exportExcel(topName, list, "服务点信息", response);
		} catch (Exception e) {
			e.printStackTrace();
		} 
     }
}
